/**
 * JAVACC DEMO 1.0
 */
package com.apache.portal.thread;

import com.apache.api.vo.ResultEntity;
import com.apache.portal.common.util.PortalPubFactory;
import com.apache.rpc.common.LoadRpcService;
import com.apache.tools.ConfigUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * description:  定时获取参数信息
 *
 * @author Hou Dayu 创建时间：2016-12-29
 */
public class CreateParamManagerInfoJob implements ISchedulerJob {

    private Logger log = LoggerFactory.getLogger(CreateParamManagerInfoJob.class);

    private static transient boolean CreateParamManagerInfoJob = true;//线程执行标志

    private static CreateParamManagerInfoJob instance;

    public CreateParamManagerInfoJob() {
    }

    public static CreateParamManagerInfoJob getInstance() {
        if (null == instance) {
            instance = new CreateParamManagerInfoJob();
        }
        return instance;
    }

    public void initParamManagerInfo() {
        initCache();
    }

    public void run() {
        try {
            if (CreateParamManagerInfoJob) {
                CreateParamManagerInfoJob = false;
                initCache();
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            CreateParamManagerInfoJob = true;
        }
    }

    private void initCache() {
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("modelTypes", "u_sysParamManager");
        param.put("resultType", "processSql");
        param.put("sqlKeyId", "ius_param");
        param.put("beforMethodKey", "ius_param");
        param.put("datasource", "plateform");
        param.put("sysPass", ConfigUtil.getInstance().interfacePass());
        ResultEntity entity = LoadRpcService.service()
                .doServiceClient(PortalPubFactory.getInstance().getBeanId(""), "dymicSql", param,
                        PortalPubFactory.getInstance().getRpcInfo("ius"));
        /**
        if (!ToolsUtil.isEmpty(entity.getEntity())) {
            List list = (List) entity.getEntity();
            for (int i = 0; i < list.size(); i++) {
                Map map = (Map) list.get(i);
                String key = map.get("formName") + "_" + map.get("pageName");
                CacheHelper.getInstance()
                        .setIusParamCache(key, map);//.getCache("").createCacheObject(key, map);
            }
        } else {
            log.error(entity.getMessage());
        }
         **/
    }

}
